package com.ebelter.temperaturegun.ui.view.temview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;


import com.ebelter.btcomlib.utils.DipUtil;
import com.ebelter.temperaturegun.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;


public class TemHisChartView extends RelativeLayout {



    public TemHisChartView(Context context) {this(context,null);}

    public TemHisChartView(Context context, AttributeSet attrs) {this(context, attrs,0);}

    public TemHisChartView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(getContext());
    }


    public static final float TopHeightWeight = 0.03f;
    public static final float ButtomHeightWeight = 0.12f;

    // 0代表°C 1代表°F
    public static final String[] Y_ITEMS_C = new String[]{"33.5","34.5","35.5","36.5","37.5","38.5","39.5","40.5","41.5"};
    public static final String[] Y_ITEMS_F = new String[]{"92.3","94.1","95.9","97.7","99.5","101.3","103.1","104.9","106.7"};

    public static float normalMinTem = 36.0f;//正常体温的范畴
    public static float normalMaxTem = 37.4f;

    public static final int EdgeIntervalNum = 2;//边沿间隔数量
    public static float ItemIntervalWeight;//间隔宽度



    private TemHisChartViewForm mTemHisChartViewForm;
    private TemHisChartViewTop mTemHisChartViewTop;

    private void initView(Context context) {
        ItemIntervalWeight = DipUtil.dip2px(getContext(),70);
        View view =  View.inflate(context, R.layout.temhischartview, this);//把那个布局当做是自己的孩子

        mTemHisChartViewForm=view.findViewById(R.id.temhischartviewform);
        mTemHisChartViewTop=view.findViewById(R.id.temhischartviewtop);
    }

    public void setDatas(List<ItemBean> datas, int selectIndex){
        if (mTemHisChartViewForm!=null){
            mTemHisChartViewForm.setDatas(datas);
            mTemHisChartViewForm.setSelectIndex(selectIndex);
        }
    }

    public void addDatas(List<ItemBean> datas){
        if (mTemHisChartViewForm!=null){
            mTemHisChartViewForm.addDatas(datas);
        }
    }

    public TemHisChartView.ItemBean getSelectItem(){
        if (mTemHisChartViewForm!=null){
            return mTemHisChartViewForm.getSelectItem();
        }
        return null;
    }

    //0代表°C 1代表°F
    public void setUnitModel(int unit){
        if (mTemHisChartViewTop!=null){
            mTemHisChartViewTop.setUnitModel(unit);
        }
    }

    public static class ItemBean{
        public int index;
        public float value;
        public String date;
        public String time;
        public int itemTotalNum;
        public int tempType;
        public String testDate;

        @Override
        public String toString() {
            return "ItemBean{" +
                    "index=" + index +
                    ", value=" + value +
                    ", date='" + date + '\'' +
                    ", time='" + time + '\'' +
                    ", itemTotalNum=" + itemTotalNum +
                    ", tempType=" + tempType +
                    ", testDate='" + testDate + '\'' +
                    '}';
        }
    }

    public void setSelect(int select){
        if (mTemHisChartViewForm!=null)mTemHisChartViewForm.setSelectIndex(select);
    }




    public void setItemSelectListener(ItemSelectListener itemSelectListener) {
        if (mTemHisChartViewForm!=null)mTemHisChartViewForm.setItemSelectListener(itemSelectListener);
    }

    public interface ItemSelectListener{
        void selectChange(int selectIndex, TemHisChartView.ItemBean itemBean);
    }


    //设置左右监听
    public void setLeftRightScorllListener(TemHisChartViewForm.LeftRightScorllListener mLeftRightScorllListener){
        if (mTemHisChartViewForm!=null)mTemHisChartViewForm.setLeftRightScorllListener(mLeftRightScorllListener);
    }


}
